#ifndef TASKMANGER_H
#define TASKMANGER_H

#include "stdint.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define TASK_PRIO_MAX 64
#define TASK_TASK_STATE_SLEEP 0
#define TASK_TASK_STATE_ACTIVE 1

	typedef struct OST_CB
	{
		uint8_t Priority;
		uint8_t TaskSt;
		struct OST_CB *NextTask;
		void (*TaskPtr)(void);
	} TASK_TCB;

	void os_task_init(void (*TaskSwHook)(void));
	void os_task_add(TASK_TCB *TaskTCB, uint8_t Prio, void (*TaskPtr)(void));
	void os_task_del(TASK_TCB *TaskTCB);
	void os_task_run(void);
	void os_task_pend(TASK_TCB *TCB);
	void os_task_post(TASK_TCB *TCB);

	void task_enable_irq(void);
	void task_disable_irq(void);

	typedef struct
	{
		int8_t tail_site;
		int8_t max_site;
		void (**list)(void);
		void (*switchHook)(void);
	} vtask_vector_type;

	void vtask_list_init(vtask_vector_type *vect, void (**list)(void), uint8_t taskmax, void (*sw_hook)(void));

	int8_t vtask_list_add(vtask_vector_type *vect, void (*TaskPtr)(void));
	int8_t vtask_list_del(vtask_vector_type *vect, void (*TaskPtr)(void));

	void vtask_list_run(vtask_vector_type *vect);
	void vtask_list_run_nohook(vtask_vector_type *vect);
	void vtask_list_run_once(vtask_vector_type *vect);
	void vtask_list_run_once_nohook(vtask_vector_type *vect);

	struct vtask_cb_str
	{
		void (*task)(void);
		struct vtask_cb_str *next;
	};

	typedef struct vtask_cb_str vtask_cb_type;

	struct vtask_manage_str
	{
		void (*switch_hook)(void);
		vtask_cb_type *list;
	};
	typedef struct vtask_manage_str vtask_manage_type;

	void vtask_init(vtask_manage_type *vect, void (*sw_hook)(void));
	void vtask_add(vtask_manage_type *vect, vtask_cb_type *task_cb, void (*task)(void));
	void vtask_del(vtask_manage_type *vect, vtask_cb_type *task_cb);
	void vtask_run(vtask_manage_type *vect);
	void vtask_run_nohook(vtask_manage_type *vect);
	void vtask_run_once(vtask_manage_type *vect);
	void vtask_run_once_nohook(vtask_manage_type *vect);

#ifdef __cplusplus
}
#endif

#endif 
